package com.tjh.springbootapi.实例demo;

import com.koala.apiprototype.utils.reflect.ReflectUtils;
import com.tjh.springbootapi.entity.ReflecUtilsEntity1;
import com.tjh.springbootapi.entity.ReflecUtilsEntity2;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by koala on 2020-03-20
 */
@SpringBootTest
public class UseReflectUtils {

    /**
     * 测试单个克隆
     */
    @Test
    public void testSingle() {
        ReflecUtilsEntity1 reflecUtilsEntity1 = new ReflecUtilsEntity1();
        reflecUtilsEntity1.setUserName("测试单个克隆");
        ReflecUtilsEntity2 reflecUtilsEntity2 = new ReflecUtilsEntity2();
        ReflectUtils.copyProperties(reflecUtilsEntity1, reflecUtilsEntity2);
        System.out.println(reflecUtilsEntity2);
    }

    /**
     * 测试多个克隆
     */
    @Test
    public void testList() {
        List<ReflecUtilsEntity1> reflecUtilsEntity1s = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            ReflecUtilsEntity1 reflecUtilsEntity1 = new ReflecUtilsEntity1();
            reflecUtilsEntity1.setUserName("i=" + i);
            reflecUtilsEntity1s.add(reflecUtilsEntity1);
        }

        List<ReflecUtilsEntity2> reflecUtilsEntity2s = ReflectUtils.copyProperties(reflecUtilsEntity1s, ReflecUtilsEntity2.class);
        System.out.println(reflecUtilsEntity2s);
    }

}
